﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LightSO.CMS.Model.EasyUI
{
    public class Button : ModelBase
    {
        /// <summary>
        /// Button的栏位构造方法
        /// </summary>
        /// <param name="id">表格Id</param>
        /// <param name="title">显示名称</param>
        public Button(string id, string title, string onClick, string icon = "icon-add", bool plain = true)
        {
            Id = id;
            Title = title;
            OnClick = onClick;
            Icon = icon;
            IsPlain = plain;
        }

        /// <summary>
        /// 点击事件（Javascript脚本）
        /// </summary>
        public string OnClick { get; set; }

        /// <summary>
        /// 图标
        /// </summary>
        public string Icon { get; set; }

        /// <summary>
        /// 是否重绘
        /// </summary>
        public bool IsPlain { get; set; }


        public virtual MvcHtmlString ToHtml()
        {
            var stylecss = string.Empty;
            if (!IsPlain)
                stylecss = "style='margin-right:5px;'";

            var str = string.Format("<a id=\"btn{0}\" onclick=\"{1}\" href=\"#\" class=\"easyui-linkbutton\" data-options=\"iconCls:'{2}',plain:{4}\" " + stylecss + ">{3}</a>",
                Id, OnClick, Icon, Title, IsPlain.ToString().ToLower());

            return new MvcHtmlString(str);
        }
    }
}